import { createRouter, createWebHashHistory } from 'vue-router'
import config from '../config'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/', redirect: '/home' },
    { path: '/login', component: () => import('../views/login.vue') },
    {
      path: '/home',
      component: () => import('../views/home.vue'),
      meta: {
        isHeader: true
      }
    },
    {
      path: '/report',
      component: () => import('../views/report.vue'),
      meta: {
        isHeader: true
      }
    },
    {
      path: '/questionnaire',
      name: 'questionnaire',
      component: () => import('../views/questionnaire.vue'),
      meta: {
        isHeader: true
      }
    },
    {
      path: '/result',
      name: 'result',
      component: () => import('../views/result.vue')
    }
  ]
})

router.beforeEach(async (to, from, next) => {
  if (config.routesWhiteList.includes(to.path)) {
    next()
  } else {
    // var result = await getTokenAsync()
    var result = localStorage.getItem('token')
    if (!result) {
      next('/login')
    } else {
      next()
    }
  }
})
export default router
